home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7472 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: ibm32.perftech.com!usenet
  2. From: murf@perftech.com (John Murphy)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Timer (0x1C) Interrupt exactly 18.2 seconds?
  5. Date: 23 Feb 1996 14:00:07 GMT
  6. Organization: Performance Technology Inc
  7. Message-ID: <4gkh97$i44@ibm32.perftech.com>
  8. References: <4givrv$cim@midland.co.nz>
  9. NNTP-Posting-Host: k5zba.perftech.com
  10. Mime-Version: 1.0
  11. NNTP-Posting-User: REVCO
  12. X-Newsreader: WinVN 0.93.11
  13.  
  14. In article <4givrv$cim@midland.co.nz>, lowefam@igrin.co.nz says...
  15. >
  16. >Hi
  17. >
  18. >I have a C++ Program (on DOS) in which a function is attached to the
  19. >Timer (0x1C) Interrupt.
  20. >
  21. >The function has a static int to count the number of times it has been
  22. >called. Every 'x' calls, It executes another function.
  23. >
  24. >'x' is 546, which one would expect to result in the function being
  25. >called every 30 seconds. However, it is called every 29 point
  26. >something seconds. Over 5 minutes you can see it has drifted. If I had
  27. >one to 'x' (now 547) it is called every 30 point something seconds -
  28. >the same problem in reverse.
  29. >
  30. >This program is expected to run, continually, for YEARS - so a drift
  31. >that shows up in 5 minutes will make it unusable.
  32. >
  33. >Does anybody have any ideas WHY this is happening?
  34. >
  35. The timer tick, as you have discovered, does NOT occur exactly 18.2 ticks 
  36. per second.  It is derived from a 1.19318 MHz oscillator divided by 64K, so 
  37. it's closer to 18.2065 times per second.
  38.  
  39. Try something like this in your tick interrupt code:
  40.  
  41. {
  42. static long accumulator = 0;
  43.  
  44.  
  45.     accumulator += 0x10000;    /* Number of oscillator cycles per tick */
  46.     if ( accumulator >= 1193180 * 30 ) {
  47.         accumulator -= 1193180 * 30;
  48.         /* call your "once every 30 seconds" function */
  49.         }
  50.     }
  51.  
  52. Then you'll get a timeout in a little less than 30 seconds sometimes and a 
  53. little more than 30 seconds other times, but the long term average will be 
  54. pretty good.
  55.  
  56. Murf
  57.  
  58.